/**
 * MdiTab
 * @type class
 * @since 1.0 <2015-9-17> SoChishun <14507247@qq.com> Added.
 */
var MdiTab = {
    newInstance: function () {
        /**
         * 类对象
         * @type object
         */
        var obj = {
            /**
             * 配置
             */
            config: {tab_id: '#tab_main'},
            /**
             * 初始化
             * @since 1.0 <2015-9-10> SoChishun Added.
             */
            init: function () {
                $(this.config.tab_id).tabs({
                    height: obj.get_window_height(),
                    onClose: function (title, index) {
                        // 清理内存
                        var tab = $(obj.config.tab_id).tabs('getSelected');
                        var ifrm = $(tab).find('iframe');
                        if (ifrm) {
                            ifrm.attr('src', "about:blank");
                        }
                    },
                });
            },
            /**
             * 添加导航标签
             * @param {type} menu
             * @since 1.0 <2015-9-10> SoChishun Added.
             */
            add_tab: function (title, url) {
                var scontent = '<iframe frameborder="0" scrolling="yes" style="width:100%" src="' + url + '" onload="$(this).height(mditab.get_window_height(130))"></iframe>';
                $(this.config.tab_id).tabs('add', {
                    title: title,
                    content: scontent,
                    closable: true,
                    tools: [{
                            iconCls: 'icon-mini-refresh',
                            handler: function () {
                                var ifrm = $(obj.config.tab_id).tabs('getSelected').find('iframe');
                                var src = ifrm.attr('src');
                                ifrm.attr('src', "about:blank").attr('src', src);
                            }
                        }],
                });

            },
            /**
             * 关闭所有标签
             * @since 1.0 <2015-9-17> SoChishun Added.
             */
            close_all: function () {
                var tabs = $(this.config.tab_id).tabs("tabs");
                var length = tabs.length;
                var title;
                for (var i = 0; i < length; i++) {
                    title = tabs[0].panel('options').tab.text();
                    $(this.config.tab_id).tabs("close", title);
                }
            },
            /**
             * 获取主容器高度
             * @returns Number
             * @since 1.0 2014-8-12 by sutroon
             */
            get_window_height: function (offset) {
                if (undefined == offset) {
                    offset = 100;
                }
                var winHeight = 0;
                if (window.innerHeight) {
                    winHeight = window.innerHeight;
                } else if ((document.body) && (document.body.clientHeight)) {
                    winHeight = document.body.clientHeight;
                }
                return winHeight - offset;

            }
        };
        return obj;
    }
}

